<div class="form">


<?php $form = $this->beginWidget('GxActiveForm', array(
	'id' => 'firm-additional-address-form',
	'enableAjaxValidation' => false,
));
?>

	<p class="note">
		<?php echo AdminModule::t('Поля помеченные '); ?> <span class="required">*</span> <?php echo AdminModule::t('являются обязательными'); ?>.
	</p>

	<?php echo $form->errorSummary($model); ?>
		<div class="row">
		<?php echo $form->labelEx($model,'user_id'); ?>
		<?php
            echo $form->dropDownList($model, 'user_id', GxHtml::listDataEx(Users::model()->visible()->findAllAttributes(null, true, 'usergroup_id NOT IN (4)')),
            array(
                'ajax' => array(
                    'type'=>'POST', //request type
                    'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                    'update'=>'#dropdown_firms',
                    'data'=>array('user_id'=>'js:this.value', 'pkey'=>'user_id', 'model'=>'Firms', 'ovkey'=>'id', 'olkey' => 'title', /*'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')*/),
                )
            ));
		?>
		<?php echo $form->error($model,'user_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'firm_id'); ?>
		<?php
			$user_id = 0 < $model->user_id ? $model->user_id : 1;
			$list_data = GxHtml::listDataEx(Firms::model()->visible()->findAllAttributes(null, true, 'user_id = :uid', array(':uid' => $user_id)));
			if (0 >= count($list_data)) {
				$list_data = array(0 => AdminModule::t('Не найдено фирм для выбранного пользователя'));
			}
			echo $form->dropDownList($model, 'firm_id', 
				$list_data, 
				array('id'=>'dropdown_firms')
			);         
		?>
		<?php echo $form->error($model,'firm_id'); ?>
		</div><!-- row -->
        
		<div class="row">
		<?php echo $form->labelEx($model,'country_id'); ?>
		<?php 
            echo $form->dropDownList($model, 'country_id', GxHtml::listDataEx(Countries::model()->visible()->findAllAttributes(null, true)),
            array(
                'ajax' => array(
                    'type'=>'POST', //request type
                    'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                    'data'=>array('country_id'=>'js:this.value', 'pkey'=>'country_id', 'model'=>'Regions', 'ovkey'=>'id', 'olkey' => 'name', /*'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')*/),
                    'success' => 'function(html) {
                            jQuery("#dropdown_regions").html(html);
                            jQuery("#dropdown_regions").change();
                    }'                    
                )
            ));
        ?>
		<?php echo $form->error($model,'country_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'region_id'); ?>
		<?php 
			$country_id = 0 < $model->country_id ? $model->country_id : Yii::app()->params['default_country_id'];
			echo $form->dropDownList($model, 'region_id', 
				GxHtml::listDataEx(Regions::model()->visible()->findAllAttributes(null, true, 'hidden = 0 AND country_id = :cid', array(':cid' => $country_id))), 
				array(
                    'id'=>'dropdown_regions',
                    'ajax' => array(
                        'type'=>'POST', //request type
                        'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                        'update'=>'#dropdown_cities', 
                        'data'=>array('region_id'=>'js:this.value', 'pkey'=>'region_id', 'model'=>'Cities', 'ovkey'=>'id', 'olkey' => 'name', /*'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')*/),
                    ),/*
                    'onchange'=>  GxHtml::ajax(array('type'=>'POST',
                        'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                        'update'=>'#dropdown_cities', 
                        'data'=>array('region_id'=>'js:this.value', 'pkey'=>'region_id', 'model'=>'Cities', 'ovkey'=>'id', 'olkey' => 'name', 'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')),
                    )),*/
                )
			);         
        ?>
		<?php echo $form->error($model,'region_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'city_id'); ?>
		<?php 
			$region_id = 0 < $model->region_id ? $model->region_id : Yii::app()->params['default_region_id'];
			echo $form->dropDownList($model, 'city_id', 
				GxHtml::listDataEx(Cities::model()->visible()->findAllAttributes(null, true, 'hidden = 0 AND region_id = :rid', array(':rid' => $region_id))), 
				array('id'=>'dropdown_cities')
			);                 
        ?>
		<?php echo $form->error($model,'city_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'address'); ?>
		<?php echo $form->textArea($model, 'address',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'address'); ?>
		</div><!-- row -->

<?php
echo GxHtml::submitButton(AdminModule::t('Сохранить'));
$this->endWidget();
?>
</div><!-- form -->